package cn.softwin.controller.customer;

import cn.softwin.pojo.CstCustomer;
import cn.softwin.pojo.CstCustomerDetail;
import cn.softwin.service.impl.CustumerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateCutomerById")
public class UpdateCustomerById extends HttpServlet {

    CustumerServiceImpl custumerService = new CustumerServiceImpl();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Long custId = Long.valueOf(request.getParameter("custId"));
        String custName = request.getParameter("custName");
        String custSource = request.getParameter("custSource");
        String custIndustry = request.getParameter("custIndustry");
        String custLevel = request.getParameter("custLevel");
        String custPhone = request.getParameter("custPhone");
        String custMobile = request.getParameter("custMobile");
        CstCustomer cstCustomer = new CstCustomer(custId,custName,custSource,custIndustry,custLevel,custPhone,custMobile);
        String custRegion = request.getParameter("custRegion");
        Long custCapital = Long.valueOf(request.getParameter("custCapital"));
        String custAddress = request.getParameter("custAddress");
        String custZip = request.getParameter("custZip");
        String custFax = request.getParameter("custFax");
        String custWebsite = request.getParameter("custWebsite");
        String custLicence = request.getParameter("custLicence");
        String custMemo = request.getParameter("custMemo");
        String custBank = request.getParameter("custBank");
        String custPic = request.getParameter("custPic");
        CstCustomerDetail cstCustomerDetail = new CstCustomerDetail(custId,custRegion, custZip,custAddress,custFax,custWebsite,custLicence,custCapital,custBank,custPic,custMemo);
        Boolean flag1 = custumerService.updateCustomerById(cstCustomer);
        Boolean flag2 = custumerService.updateCustomerDetailById(cstCustomerDetail);
        if (flag1&flag2) {
            request.getRequestDispatcher("/queryCustomerServlet").forward(request, response);
        } else {
            request.getRequestDispatcher("error.jsp").forward(request,response);
        }
    }

    /**
     * Description: 根据id完成客户信息的回显和修改
     * Author: zhangxiangkai
     * Params: [request, response]
     * ReturnType: void
     * Time: 2021/2/18-19:28
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);


    }
}
